package com.galaxy.service.controller.system;

import com.baomidou.mybatisplus.plugins.Page;
import com.galaxy.commom.base.annotation.WebLog;
import com.galaxy.commom.base.message.ResponseCode;
import com.galaxy.commom.base.message.ResponseResult;
import com.galaxy.service.dto.system.role.QueryRoleDto;
import com.galaxy.service.dto.system.role.RoleAddDto;
import com.galaxy.service.dto.system.role.RoleUpdateDto;
import com.galaxy.service.entity.system.Role;
import com.galaxy.service.service.system.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色控制器
 * @author caijinbang
 * @date 2018/10/28 00:01
 */
@RestController
@Api(tags = {"角色管理接口"})
@RequestMapping(value = {"/system/role"})
public class RoleController {

  @Autowired
  private RoleService roleService;

  /**
   * 新增角色
   * @param roleAddDto
   * @return
   */
  @PostMapping("/add")
  @ApiOperation(value = "添加新增")
  @WebLog("添加新增")
  @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
  public ResponseResult add(@RequestBody @Validated RoleAddDto roleAddDto){
    roleService.add(roleAddDto);
    return ResponseResult.e(ResponseCode.OK);
  }

  /**
   * 获取角色列表
   * @param id
   * @param roleUpdateDto
   * @return
   */
  @PostMapping("/update/{id}")
  @ApiOperation(value = "更新指定ID对象的信息")
  @WebLog("更新指定ID对象的信息")
  @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
  public ResponseResult update(@PathVariable("id") String id, @RequestBody @Validated RoleUpdateDto roleUpdateDto){
    roleService.update(id,roleUpdateDto);
    return ResponseResult.e(ResponseCode.OK);
  }

  /**
   * 分页获取所有角色列表
   * @param queryRoleDto
   * @return
   */
  @PostMapping("/list")
  @ApiOperation(value = "分页获取所有角色列表")
  @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
  public ResponseResult<Page<Role>> list(@RequestBody QueryRoleDto queryRoleDto){
    Page<Role> rolePage = roleService.list(queryRoleDto);
    return ResponseResult.e(ResponseCode.OK,rolePage);
  }


  /**
   * 根据角色id删除角色
   * @param id
   * @return
   */
  @PostMapping("/remove/{id}")
  @ApiOperation(value = "删除指定ID的对象")
  @WebLog("删除指定ID的对象")
  @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token",required = true)
  public ResponseResult remove(@PathVariable("id") String id){
    roleService.remove(id);
    return ResponseResult.e(ResponseCode.OK);
  }

}
